package ClassDay5.CONFIG;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
public class MybaitsConfig {
    @Bean
    public SqlSessionFactoryBean GetBeanFactory(DataSource ds){

        SqlSessionFactoryBean d=new SqlSessionFactoryBean();


        d.setDataSource(ds);
        return  d;
    }
    @Bean
    public MapperScannerConfigurer Ma(){
        MapperScannerConfigurer mc=new MapperScannerConfigurer();
        mc.setBasePackage("ClassDay5.IN");
        return mc;
    }
    @Bean
    public DataSource getDurid(){
        DruidDataSource dds=new DruidDataSource();
        dds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dds.setUsername("root");
        dds.setPassword("123456");
        dds.setUrl("jdbc:mysql://127.0.0.1/新锋web");
        return  dds;
    }
    @Bean//你不配置事务管理器吗?参数是一种暴力反射
    public DataSourceTransactionManager GetTranManner(DataSource da){
        DataSourceTransactionManager dstm=new DataSourceTransactionManager();
        dstm.setDataSource(da);
        return dstm;
    }
}
